package com.hzzh.service;

import java.sql.SQLException;
import java.util.ArrayList;

import com.hzzh.dao.EmployeeDAO;
import com.hzzh.vo.Employee;

public class EmployeeService {

	private EmployeeDAO dao=new EmployeeDAO();
	
	private Employee loginedEmployee = new Employee();
	
	public int login(String username,String password) throws ClassNotFoundException, SQLException{
		int flag=3;
		Employee e=dao.SelectByNamePwd(username, password);
		
		if(e!=null){
			loginedEmployee =e;
			String status=e.getStatus();
			
			if(status!=null&&status.equals("1")){
				flag=1;
			}if(status!=null&&status.equals("0")){
				flag=0;
			}if(status!=null&&status.equals("2")){
				flag=2;
			}
			
		}
		return flag;
	}
	
	//
	public Employee getLoginedEmployee(){
		return loginedEmployee;
	}
	
	
	//显示审批列表
		public ArrayList<Employee> selectAllEmployeesService() throws ClassNotFoundException, SQLException{
			EmployeeDAO ed = new EmployeeDAO();
			ArrayList<Employee> al = ed.selectAllEmployeesDAO();
			return al;		
		}
		//修改status
		public void updateStatusService(int employeeid,String status) throws ClassNotFoundException, SQLException{
			EmployeeDAO ed = new EmployeeDAO();
	        ed.updateStatusDAO(employeeid, status);
		}
		
		// 分页
			private int countOfEmployees;
			private int countOfPages;
			private int pageSize = 3;
			
		//搜索员工,总数
		public ArrayList<Employee> selectEmployeesByNameStatuService(String employeename,String username,String status) throws ClassNotFoundException, SQLException{
			EmployeeDAO ed = new EmployeeDAO();
			ArrayList<Employee> al = ed.selectEmployeesByNameStatusDAO(employeename, username, status);
			countOfEmployees = al.size();
			return al;
		}
		//查询每一页的数据集合
		public ArrayList<Employee> selectEmployeesOfOnePageService(String employeename,String username,String status,int pageSize,int pageNum) throws ClassNotFoundException, SQLException{
			EmployeeDAO ed = new EmployeeDAO();
	        return ed.selectEmployeesOfOnePageDAO(employeename, username, status, pageSize, pageNum);				
		}
		//查询总页数
		public int getCountOfPagesService() throws ClassNotFoundException, SQLException{
	        countOfPages=(countOfEmployees%pageSize==0) ? countOfEmployees/pageSize : countOfEmployees/pageSize+1;
			return this.countOfPages;
		}
		//返回所有记录条数
		public int getCountOfEmployeesService(){
			return this.countOfEmployees;
		}
		//pageSize = 3
		public int getPageSizeService(){
			return this.pageSize;
		}
	
}
